/**
 * @param {string} word
 * @return {number}
 */
var addMinimum = function(word) {
    const stack = []
    let i = 0, ans = 0
    while(i < word.length) {
        while(stack.length >= 3 && stack[len - 3] == "a" && stack[len - 2] == "b" && stack[len - 1] == "c") {
            stack.pop()
            stack.pop()
            stack.pop()
        }
        if(stack.length !== 0) {
            if(stack[stack.length - 1] == "a" && word.charAt(i) == "b") {
                stack.push("b")
                i++
            } else if(stack[stack.length - 1] == "b" && word.charAt(i) == "c") {
                stack.push("c")
                i++
            }
        } else if(stack.length == 0) {
            if(word.charAt(i) == 'a') {
                stack.push("a")
                i++
            } else if(word.charAt(i) == 'b') {
                stack.push('a')
                ans++
            } else {
                stack.push("a", "b")
                ans += 2
            }
        }

    }
};